<template>
  <div>
    <div class="table-operator" v-if="stage !== '05010' && stage !== '05050'">
      <a-button :disabled="status == '9' || status == '2' || status == '3'" v-permission="['30010']" type="primary" @click="showConfirm">
        提交审核
      </a-button>
      <a-button :disabled="status !== '2'" v-permission="['30020']" @click="setApproveReason('9')"> 同意</a-button>
      <a-button
        :disabled="status !== '2'"
        style="margin-top: 10px"
        v-permission="['30020']"
        type="danger"
        @click="setApproveReason('1')"
      >
        拒绝
      </a-button>
      <template>
        <a-divider type="vertical" />
        <a-button v-permission="['30010']" type="primary" @click="generateCg" :disabled="status == '9' || status == '2' || status == '3'">
          生成
        </a-button>
      </template>
    </div>
    <a-table
      ref="table"
      size="middle"
      bordered
      rowKey="id"
      :columns="columns"
      class="table_header_blue"
      :dataSource="dataSource"
      :pagination="false"
      :loading="loading"
    >
      <span slot="actionName">
        <a-space v-if="stage !== '05010' && stage !== '05050'" v-permission="['30010']">
          <a-button size="small" @click="downLoadTemplete()" type="primary" icon="download">
            模板下载
          </a-button>
          <a-upload
            v-if="stage !== '05010' && stage !== '05050'"
            :disabled="status == '9' || status == '2' || status == '3'"
            v-permission="['30010']"
            :data="fileData"
            name="files"
            :showUploadList="false"
            :multiple="false"
            :headers="tokenHeader"
            :action="url.upLoad"
            @change="handleImportExcel2"
            accept=".docx, .doc, .xlsx, .xls, .pdf, .jpeg, .png"
          >
            <a-button size="small" type="primary" icon="import" :disabled="status == '9' || status == '2' || status == '3'">上传</a-button>
          </a-upload>
        </a-space>
        <span v-else>操作</span>
      </span>
      <span slot="action" slot-scope="text, record">
        <a @click="OnPerview(record)">预览</a>
        <a-divider type="vertical" />
        <a @click="OnDownLoad(record)">下载</a>
      </span>
    </a-table>
    <SelectApprove ref="approver" :id="id" @submitData="handleSubmit"></SelectApprove>
    <SetReason ref="setReason" @approveReason="approveData"></SetReason>
    <TempleteDownload ref="templeteDownload" :type="tempType" :url="url.templateUrl" />
  </div>
</template>

<script>
import { filePerviewMixin } from '@/mixins/filePerviewMixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { butStatus } from '../public/butStatus'
import SelectApprove from '../public/SelectApprover'
import SetReason from '../public/SetReason'
import columns from './indexColumns'
import TempleteDownload from '@views/sj/components/TempleteDownload.vue'
import { postAction } from '@api/manage'

export default {
  name: 'zqyjg',
  mixins: [JeecgListMixin, filePerviewMixin, butStatus],
  components: {
    TempleteDownload,
    SelectApprove,
    SetReason
  },
  props: ['id', 'type', 'stage'],
  data() {
    return {
      queryParam: {
        id: this.id,
        typeId: this.type
      },
      fileData: {
        biz: 'baogao_cg',
        type: 'baogao_cg',
        proId: this.id
      },
      typeId: this.type,
      bgType: 'baogao_cg',
      statusKey: 'cg',
      //表头
      columns: columns(this),
      url: {
        list: '/sjxmzygl/sjWorkBaogao/queryAuditReportInfo',
        submit: '/sjxmzygl/sjWorkUsers/submitAudit',
        approve: '/sjxmzygl/sjWorkUsers/zyApplyCommit',
        saveBg: '/sjxmzygl/sjWorkBaogao/saveBg',
        upLoad: `${window._CONFIG['domianURL']}/sys/common/sjBgUpload`,
        templateUrl: '/xtsz/sjWordTemplate/list',
        generateCg: '/sjxmzygl/sjWorkBaogao/generateCg'
      },
      tempType: 'baogao_cg'
    }
  },
  created() {
  },
  methods: {
    generateCg() {
      postAction(this.url.generateCg, {
        proId: this.queryParam.id,
        type: this.bgType
      }).then((res) => {
        if (res.success) {
          this.$message.success(res.message)
          this.loadData()
        } else {
          this.$message.error(res.message)
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
@import '~@assets/less/tableTheme.less';
</style>